﻿@using System.Drawing
@model List<Kybotech.Paragon.Responses.BookingWindow>
@{
    Kybotech.Paragon.Responses.BookingWindow bestBookingWindow = null;
    foreach (var bookingWindowItem in Model)
    {
        if (bookingWindowItem.AvailableToBook &&
            (bestBookingWindow == null ||

            (bestBookingWindow.Greenness < bookingWindowItem.Greenness) ||

            (bestBookingWindow.Greenness == bookingWindowItem.Greenness &&
                bestBookingWindow.MarginalCost > bookingWindowItem.MarginalCost &&
                bookingWindowItem.MarginalCost != 0)
            ))
        {
            bestBookingWindow = bookingWindowItem;
        }
    }
}
<script>
    $(".tbl-listbookingwindow tbody tr").click(function () {
        $(this).addClass("row-selected");
        $(".tbl-listbookingwindow tbody tr").not(this).removeClass('row-selected');
    });
</script>
<table class="table table-bordered  tbl-listbookingwindow floatThead-table">
                    <thead>
                        <tr>
                            <th>Day</th>
                            <th>Date</th>
                            <th>TimeSlot</th>
                            <th>MarginalCost</th>
                            <th>Greeness</th>
                            <th>DelO Uname</th>
                            <th>Window Text</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            var backColor = "#FFFFFF";
                            var foreColor = "#FFFFFF";
                            // colouring the row base on the availability
                            if (!item.AvailableToBook)
                            {
                                backColor = "#E6B7B7";
                                foreColor = "#808080";
                            }
                            else
                            {

                                // hightlight the lowest marginal cost
                                if (item == bestBookingWindow)
                                {
                                    foreColor = "blue";
                                }
                                else {foreColor = "green";}
                                backColor = "#D8E4BC";
                            }
                            <tr onclick="SelectedAvaibleDateChanged('@item.DeliveryDate.ToString("dd-MMM-yyyy")')" style="background-color: @backColor;color: @foreColor">
                                <td>@item.DeliveryDate.DayOfWeek.ToString()</td>
                                <td>@item.DeliveryDate.ToString("dd-MMM-yyyy")</td>        
                                <td>@item.TimeSlotName</td>
                                <td>@item.MarginalCost</td>        
                                <td>@item.Greenness</td>
                                <td>@item.DelOUName</td>              
                                <td>@item.WindowText</td>
                            </tr>
                        }                
                    </tbody>
                </table>